home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 40
/
Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso
/
Aminet
/
util
/
cdity
/
ModeProSrc.lha
/
Prefs
/
MPPReadArgs.c
< prev
next >
Wrap
C/C++ Source or Header
|
1999-02-14
|
6KB
|
239 lines
#include <proto/dos.h>
#include <proto/icon.h>
#include <workbench/workbench.h>
#include "/modepro.h"
#include "mpp.h"
BOOL GetReadArgs(void);
BOOL RAYesNo(STRPTR Str, BOOL DefVal);
ULONG RAInt(ULONG *Val,ULONG DefVal);
STRPTR RAString(STRPTR Str, STRPTR DefVal);
BOOL GetToolTypes(int argc, char **argv);
struct RDArgs *RArgs=0;
LONG UseTT=0;
extern ULONG Arg_Promo, Arg_NLM, Arg_Ask, Arg_CH, Arg_CV, Arg_Debug, Arg_Import;
UBYTE RATemplate[]="FROM,"
"EDIT/S,"
"USE/S,"
"SAVE/S,"
"PUBSCREEN/K,"
"PRO=ENABLE_PROMOTION/K,"
"NLM=NEWLOOKMENUS/K,"
"ASK=ASK_UNKNOWN/K,"
"CH=CENTER_HORZ/K,"
"CV=CENTER_VERT/K,"
"FN=FONT_NAME/K,"
"FS=FONT_SIZE/K/N,"
"IMPORT/K,"
"DEBUG/K";
LONG RAResults[14]={0};
#define FROM 0
#define EDIT 1
#define USE 2
#define SAVE 3
#define PUBSCREEN 4
#define RA_PROMO 5
#define RA_NLM 6
#define RA_ASK 7
#define RA_CAH 8
#define RA_CAV 9
#define FNAME 10
#define FSIZE 11
#define RA_IMPORT 12
#define RA_DEBUG 13
WORD ArgMode;
struct DiskObject *MPIcon;
BPTR OldDirLock;
BOOL GetArgs(int argc, char **argv)
{
BPTR lock;
ArgMode=min(argc,2);
switch(ArgMode)
{
case 0:
return(GetToolTypes(argc,argv));
break;
case 1:
{
char pname[256];// (4.61.4)
// (4.61.4)
if(GetProgramName(pname,256))// (4.61.4)
{// (4.61.4)
if(lock=DupLock(GetProgramDir()))// (4.61.4)
{// (4.61.4)
OldDirLock=CurrentDir(lock);// (4.61.4)
if(MPIcon=GetDiskObject(pname))// (4.61.4)
{// (4.61.4)
LONG l;
for(l=0;MPIcon->do_ToolTypes[l];l++); // <- Note SEMI-COLON, Count ToolTypes
return(GetToolTypes(l,MPIcon->do_ToolTypes));
}
}
}
}
return(0);
case 2: // Shell Mode.
return(GetReadArgs());
}
}
void CleanupArgs(void)
{
BPTR lock;
switch(ArgMode)
{
case 0:
ArgArrayDone();
break;
case 1:
ArgArrayDone();
FreeDiskObject(MPIcon);
lock=CurrentDir(OldDirLock);// (4.56.2)
UnLock(lock);// (4.56.2)
break;
case 2:
FreeArgs(RArgs);
break;
}
}
extern ULONG ArgEdit,ArgUse,ArgSave;
extern STRPTR ArgFrom,ArgPubscreen;
extern UBYTE *UserFontName;
extern LONG UserFontSize;
BOOL GetReadArgs(void)
{
if(RArgs=ReadArgs(RATemplate,RAResults,0))
{
if((Arg_Import =(STRPTR)RAResults[RA_IMPORT]))
{
ArgEdit=TRUE;
}
else
{
ArgFrom =(STRPTR)RAResults[FROM];
ArgEdit =RAResults[EDIT];
ArgUse =RAResults[USE];
ArgSave =RAResults[SAVE];
if(!ArgSave && !ArgUse)
ArgEdit=TRUE;
}
ArgPubscreen =(STRPTR)RAResults[PUBSCREEN];
UserFontName =(STRPTR)RAResults[FNAME];
UserFontSize =RAInt ((ULONG *)RAResults[FSIZE],8);
Arg_Promo =RAYesNo((STRPTR)RAResults[RA_PROMO] ,5);
Arg_NLM =RAYesNo((STRPTR)RAResults[RA_NLM] ,5);
Arg_Ask =RAYesNo((STRPTR)RAResults[RA_ASK] ,5);
Arg_CH =RAYesNo((STRPTR)RAResults[RA_CAH] ,5);
Arg_CV =RAYesNo((STRPTR)RAResults[RA_CAV] ,5);
Arg_Debug =RAYesNo((STRPTR)RAResults[RA_DEBUG] ,5);
// printf("Exiting GRS\n");
return(TRUE);
}
else
PrintFault(IoErr(),0);
return(FALSE);
}
BOOL RAYesNo(STRPTR Str, BOOL DefVal)
{
BOOL retval;
retval=DefVal;
if(Str)
{
switch(*Str)
{
case 'T':
case 't':
case 'Y':
case 'y':
retval=1;
break;
case 'F':
case 'f':
case 'N':
case 'n':
retval=0;
}
}
return(retval);
}
ULONG RAInt(ULONG *Val,ULONG DefVal)
{
if(Val)
return(*Val);
return(DefVal);
}
STRPTR RAString(STRPTR Str, STRPTR DefVal)
{
if(Str)
return(Str);
return(DefVal);
}
BOOL GetToolTypes(int argc, char **argv)
{
UBYTE **ttypes;
UseTT=TRUE;
ttypes =ArgArrayInit(argc,argv);
if((Arg_Import =ArgString(ttypes,(UBYTE *)"IMPORT",0)))
{
ArgEdit=TRUE;
}
else
{
ArgFrom =ArgString(ttypes,(UBYTE *)"FROM",0);
ArgEdit =(ULONG)FindToolType(ttypes,"EDIT");
ArgUse =(ULONG)FindToolType(ttypes,"USE");
ArgSave =(ULONG)FindToolType(ttypes,"SAVE");
if(!ArgSave && !ArgUse)
ArgEdit=TRUE;
}
ArgPubscreen =ArgString(ttypes,(UBYTE *)"PUBSCREEN",0);
UserFontName =ArgString(ttypes,(UBYTE *)"FONT_NAME",0);
UserFontSize =ArgInt (ttypes,(UBYTE *)"FONT_SIZE",8);
Arg_Promo =ArgYesNo (ttypes,(UBYTE *)"ENABLE_PROMOTION",5);
Arg_NLM =ArgYesNo (ttypes,(UBYTE *)"ENABLE_NLM",5);
Arg_Ask =ArgYesNo (ttypes,(UBYTE *)"ASK_UNKNOWN",5);
Arg_CH =ArgYesNo (ttypes,(UBYTE *)"CENTER_HORIZ",5);
Arg_CV =ArgYesNo (ttypes,(UBYTE *)"CENTER_VERT",5);
Arg_Debug =ArgYesNo (ttypes,(UBYTE *)"DEBUG",5);
Arg_Import =ArgString(ttypes,(UBYTE *)"IMPORT",0);
return(TRUE);
// return(FALSE);
}